package wzyouxibao;
 class Hero{
    private String name;
    private String role;
    private int hp;
    private int attack;
    private int defense;
    private int magicResist;
    private int moveSeepd;
    private int level;
    private int exp;
    private String[] skills;

    public Hero(String name,String role,int hp,int attack,int defense,int magicResist,
                int moveeSeepd,String[] skills){
        this.name=name;
        this.role=role;
        this.hp=hp;
        this.attack=attack;
        this.defense=defense;
        this.magicResist=magicResist;
        this.moveSeepd=moveeSeepd;
        this.level=1;
        this.exp=0;
        this.skills=skills;
    }

    public String getName(){
        return name;
    }

    public String getRole(){
        return role;
    }

    public int getHp(){
        return hp;
    }

    public void setHp(int hp){
        this.hp=hp;
    }

    public int getAttack(){
        return attack;
    }

    public void setAttack(int attack){
        this.attack=attack;
    }

    public int getDefense(){
        return defense;
    }

    public void setDefense(int defense){
        this.defense=defense;
    }

    public int getMagicResist(){
        return magicResist;
    }

    public void setMagicResist(int magicResist){
        this.magicResist=magicResist;
    }

    public int getMoveSeepd(){
        return moveSeepd;
    }

    public void setMoveSeepd(int moveSeepd){
        this.moveSeepd=moveSeepd;
    }

    public int getLevel(){
        return level;
    }

    public int getExp(){
        return exp;
    }

    public String[] getSkills(){
        return skills;
    }

    public void levelUp(){
        level++;
        hp +=100;
        attack+=10;
        defense+=5;
        magicResist+=5;
        System.out.println(name + "升级了！当前等级：" + level);
    }

    public void gainExp(int exp){
        this.exp+=exp;
        System.out.println(name + "获得了" + exp + "点经验");
        if (this.exp>=100){
            levelUp();
            this.exp-=100;
        }
    }
    //重载normalAttack方法
    public void normalAttack(Hero target){
        int damage=attack-target.getDefense()/2;
        if (damage<0)damage=0;
        target.setHp(target.getHp()-damage);
        System.out.println(name+"对"+target.getName()+"造成了"+damage+"点伤害");
    }

    public void normalAttack(Hero target,boolean isCritical){
        int baseDamage=attack-target.getDefense()/2;
        int damage=isCritical?baseDamage*2:baseDamage;
        if (damage<0)damage=0;

        target.setHp(target.getHp()-damage);
        System.out.println(name+"对"+target.getName()+"造成了"+damage+"点伤害"+(isCritical?"(暴击！)":""));
    }

    public void useSkill(int skillIndex,Hero target){
        if(skillIndex<0||skillIndex >=skills.length){
            System.out.println("无效的技能索引");
            return;
        }

        String skill=skills[skillIndex];
        int damage=attack *(1+skillIndex)-target.getDefense()/2;
        if (damage<0)damage=0;
        target.setHp(target.getHp()-damage);
        System.out.println(name+"使用"+skill+"对"+target.getName()+"造成了"+damage+"点伤害");
    }

    public boolean isAlive(){
        return hp>0;
    }

    public void displayStatus(){
        System.out.println("==="+name+"状态===");
        System.out.println("定位"+role);
        System.out.println("等级："+level);
        System.out.println("生命值："+hp);
        System.out.println("攻击力："+attack);
        System.out.println("防御力："+defense);
        System.out.println("魔法抗力："+magicResist);
        System.out.println("移动速度："+moveSeepd);
        System.out.println("当前经验："+exp+"/100");
        System.out.println("技能"+String.join("，",skills));
    }

}

public class Wzyingxiong {
    public static void main(String[] args){
        String[] zhaoyunSkills={"龙鸣","破云之龙","天翔之龙"};
        Hero zhaoyun=new Hero("赵云","战士",2000,150,80,60,380,zhaoyunSkills);

        String[] houyiSkills={"多重箭矢","落日余晖","灼日之矢"};
        Hero houyi=new Hero("后羿","射手",1500,180,50,50,360,houyiSkills);

        zhaoyun.displayStatus();
        System.out.println();
        houyi.displayStatus();
        System.out.println();

        zhaoyun.normalAttack(houyi);
        zhaoyun.normalAttack(houyi,true);//normalAttack重载的测试
        houyi.useSkill(0,zhaoyun);
        zhaoyun.useSkill(2,houyi);

        zhaoyun.gainExp(120);
        houyi.gainExp(80);

        System.out.println("\n战斗后状态：");
        zhaoyun.displayStatus();
        System.out.println();
        houyi.displayStatus();

        System.out.println("\n赵云存活状态："+ zhaoyun.isAlive());
        System.out.println("后羿存活状态：" + houyi.isAlive());
    }
}

